*------------------------------------------------------------------------------*
				*** TABLE S7. USING ALTERNATIVE RADIUSES ***
*------------------------------------------------------------------------------*

***PROGRAM FOR VOTING OUTCOMES
cap program drop reg_tab_radius
program define reg_tab_radius, sclass
	args cmd spec 
	
	// THE FOLLOWING LOOP RUNS THE ANALYSIS SEPARATELY FOR ALL DEPENDENT VARIABLES
	local Y : word count $depvars_tab_radius // PICKS EACH VARIABLE ONE BY ONE FROM MACRO
	forvalues i=1/`Y' {
		local y : word `i' of $depvars_tab_radius
		`cmd' `y' ${spec`spec'} // THIS RUNS THE REGRESSION
		estadd ysumm
		
		mat b = e(b) // THIS SAVES THE COEFFICIENT VECTOR
		scalar bPM10_`spec'_`i'=b[1,1] // PM10 coefficient
		
		mat V = e(V) // THIS SAVES THE VARIANCE MATRIX
		
		// THE FOLLOWING SAVES STANDARD ERRORS, R2 AND N AS SCALARS
		scalar sePM10_`spec'_`i'  =sqrt(V[1,1]) // PM10 SE
		scalar r2`spec'_`i'  = e(r2) // r-squared
		scalar N`spec'_`i'  = e(N) // N
		scalar YM`spec'_`i' = e(ymean)  // Mean Dep. Var.
		
		// THE FOLLOWING PRODUCES SIGNIFICANCE STARS AND SAVES THEM AS LOCALS
		local pPM10_`spec'_`i'=2*(1-normal(abs(bPM10_`spec'_`i'/sePM10_`spec'_`i')))
		local starPM10_`spec'_`i' ""
		if `pPM10_`spec'_`i''<.1 {	
			local starPM10_`spec'_`i' *
		}
		if `pPM10_`spec'_`i''<.05 {
			local starPM10_`spec'_`i' **
		}
		if `pPM10_`spec'_`i''<.01 {
			local starPM10_`spec'_`i' ***
		}
		global starPM10_`spec'_`i' = "`starPM10_`spec'_`i''"
	}  // i
end

*------------------------------------------------------------------------------*

***Macros
global depvars_tab_radius "Incumbent_share Est_opp_share OtherParties_share"
local demo_econ_controls "pop_tot GDP_capita employment"


// THE FOLLOWING ARE ALL THE SPECIFICATIONS WE RUN (X-VARIABLES PLUS OPTIONS)

// 20km
global spec1 "PM10_10ug_20km O3_10ug_20km temp_20km humid_rel_20km wind_speed_20km precip_20km `demo_econ_controls' turnout i.type, ${hdfe_opt}"
// 40km
global spec2 "PM10_10ug_40km O3_10ug_40km temp_40km humid_rel_40km wind_speed_40km precip_40km `demo_econ_controls' turnout i.type, ${hdfe_opt}"
// 50km
global spec3 "PM10_10ug_50km O3_10ug_50km temp_50km humid_rel_50km wind_speed_50km precip_50km `demo_econ_controls' turnout i.type, ${hdfe_opt}"


*------------------------------------------------------------------------------*

use "${tempdata}kreise_complete_all.dta", clear
set more off

*------------------------------------------------------------------------------*

***Generate PM10 and Ozone in tens of micrograms
foreach r in 20 40 50 {
	foreach p in PM10 O3 {
		gen `p'_10ug_`r'km = `p'_`r'km /10
	} // p
} // p

*------------------------------------------------------------------------------*

***Regressions
forvalues j=1/3 {
	qui reg_tab_radius reghdfe `j'
}

*------------------------------------------------------------------------------*

***Generate table
gen str table=""

// PM10 coefficients
local i=1
local line "PM10 ($10\mu g / m^3$)&"
local line "`line'" $f_b bPM10_1_1 "\sym{$starPM10_1_1}" "&" $f_b bPM10_2_1 "\sym{$starPM10_2_1}" "&" $f_b bPM10_3_1 "\sym{$starPM10_3_1}" " \\ "
local line: display "`line'" 
qui replace table="`line'" in `i'
// PM10 s.e.
local i=`i'+1
local line "&" "(" $f_se sePM10_1_1 ")" "&" "(" $f_se sePM10_2_1 ")" "&" "(" $f_se sePM10_3_1 ")" " \\ " 
local line: display "`line'" 
qui replace table="`line'" in `i'
// Y mean
local i=`i'+1
local line "Mean dep. var.&"
local line "`line'" $f_YM YM1_1 "&" $f_YM YM2_1 "&" $f_YM YM3_1 " \\ "
local line: display "`line'" 
qui replace table="`line'" in `i'
// R2
local i=`i'+1
local line "R$^2$ & "
local line "`line'" $f_r2 r21_1 "&" $f_r2 r22_1 "&" $f_r2 r23_1 " \\ " 
local line: display "`line'" 
qui replace table="`line'" in `i'
// Observations
local i=`i'+1
local line "N&"
local line "`line'" $f_N N1_1 "&" $f_N N2_1 "&" $f_N N3_1 " \\ "
local line: display "`line'" 
qui replace table="`line'" in `i'
// CONTROLS
local i=`i'+1
qui replace table="\multicolumn{4}{l}{\textit{Controls} } \\ " in `i'
local i=`i'+1
qui replace table="\ \ County FE & \checkmark & \checkmark & \checkmark \\" in `i'
local i=`i'+1
qui replace table="\ \ El. Date FE & \checkmark & \checkmark & \checkmark \\" in `i'
local i=`i'+1
qui replace table="\ \ Weather & \checkmark & \checkmark & \checkmark \\" in `i'
local i=`i'+1
qui replace table="\ \ Ozone & \checkmark & \checkmark & \checkmark \\" in `i'
local i=`i'+1
qui replace table="\ \ Demographics & \checkmark & \checkmark & \checkmark \\" in `i'
local i=`i'+1
qui replace table="\ \ El. Type FE & \checkmark & \checkmark & \checkmark \\" in `i'
local i=`i'+1
qui replace table="\ \ Turnout & \checkmark & \checkmark & \checkmark  %\\" in `i'
local i=`i'+1

**Create .tex file
outfile table using "${outputs}table_S7.tex" in 1/`i', replace noquote
drop table
macro drop star*

*------------------------------------------------------------------------------*

clear

exit
